<style lang="less" scoped>
.tool-bar {
    margin-bottom: 2em;
}

.h4 {
    margin: 0.8em;
}
</style>
<style lang="less">
.expand-row .ivu-table-body {
    overflow: hidden;
}
</style>

<template>
    <div class="expand-row">
        <div class="tool-bar">
            <Button type="primary" shape="circle" icon="ios-arrow-back" @click="handleRet">返回</Button>
        </div>
        <div class="control box">
            <h4 class="h4 box-cell-1">订单号：{{order_code}}</h4>
            <div>
                <Form inline>
                    <Form-item prop="user">
                        <Select v-model="to_user" style="width:200px">
                            <Option v-for="item in users" :value="item.loginname" :key="item.loginname">{{ item.realname }}</Option>
                        </Select>
                    </Form-item>

                    <Form-item>
                        <Button type="primary" @click="handleSubmit()">发送</Button>
                    </Form-item>
                </Form>
            </div>
        </div>
        <Table highlight-row :columns="columns" :data="rows"></Table>
    </div>
</template>
<script>
import expandRow from '@/components/ExpandRow'
export default {
    data() {
        return {
            order_code: "",
            users: [],
            to_user: null,
            columns: [
                {
                    type: 'expand',
                    width: 50,
                    render: (h, params) => {
                        return h(expandRow, {
                            props: {
                                row: params.row,
                                oper:true
                            }
                        })
                    }
                },
                {
                    title: '物资名称',
                    key: 'comdity_name'
                },
                {
                    title: '供应商名称',
                    key: 'supplier_name'
                },
                {
                    title: '单位',
                    key: 'units'
                },
                {
                    title: '购买数量',
                    key: 'buy_number'
                },
                {
                    title: '回填数量',
                    key: 'follow_number'
                },
                {
                    title: '状态',
                    key: 'finish',
                    render: (h, params) => {
                        let val = params.row[params.column.key]
                        let text = val ? '完成' : '未完成'
                        let cls = val ? 'success' : 'warning'
                        return h("Tag", {
                            'class': cls
                        }, [text])
                    }
                },

            ],
            rows: [

            ]
        }
    },
    computed: {

    },
    mounted() {
        this.order_code = this.$route.params["order_code"]
        this.$store.dispatch('audit_users').then(resp => {
            this.users = resp.data.items
        })
        this.$store.dispatch('detail', { order_code: this.order_code }).then(resp => {
            this.rows = resp.data.items
        })

    },
    methods: {
        handleRet() {
            this.$router.go(-1)
        },
        handleSubmit() {
            console.log(this.rows)
            if (!this.to_user) {
                this.$Message.warning('请选择审核人！')
                return
            }
            if (_.some(this.rows, { "finish": false })) {

            }
            this.$store.dispatch("toaudit", { to_user: this.to_user, order_code: this.order_code }).then(resp => {
                if (resp.data.errCode == '010') {
                    this.$Message.error('信息没有全部填写完成，请继续填写！')
                    return
                }
                this.$Message.success('恭喜，提交成功！')
                this.$store.commit("minusCurrent")
                this.$router.push({ name: "OrderList",params:{step:0} })


            })
        }
    }
}
</script>
